home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / vision / grafics / programm / ximgtool / imgcodec.h < prev    next >
C/C++ Source or Header  |  1995-11-25  |  4KB  |  136 lines

  1. typedef struct
  2. {
  3.   short version;
  4.   unsigned short headlen;
  5.   short planes,
  6.     pat_run,
  7.     pix_width,
  8.     pix_height,
  9.     sl_width,
  10.     sl_height;
  11. }
  12. IMG_HEADER;
  13.  
  14. /* Public struct for buffered file i/o.
  15.  * data_func must be 'read' for file input, 'write' for file output.
  16.  * It has the task to update the bytes_left entry with size of next
  17.  * data if read, size of output buffer if write, and to set the pbuf
  18.  * entry to point to the next data if read, output buffer if write.
  19.  * NOTE: Because of the structure of the below input fetch macros,
  20.  *       it is important to UPDATE (add, not set) the bytes_left
  21.  *       entry with the new data buffer size if read!
  22.  * The public struct should be used as substruct being the first
  23.  * entry in a specific struct, which holds additional data (i.e.
  24.  * data buffer pointer and data buffer size) to be used by data_func.
  25.  * Look in the main module to see what is required.
  26.  */
  27.  
  28. typedef struct fbufpub
  29. {
  30.   char *pbuf;
  31.   long bytes_left;
  32.   void (*data_func)(struct fbufpub *fp);
  33. }
  34. FBUFPUB;
  35.  
  36. /* Public struct for image data processing. */
  37.  
  38. typedef struct ibufpub
  39. {
  40.   char *pbuf;
  41.   long bytes_left;
  42.   void (*put_line)(struct ibufpub *ip);
  43.   char *pat_buf;
  44.   short pat_run;
  45.   char vrc, pad;
  46. }
  47. IBUFPUB;
  48.  
  49.  
  50. /* The following macros handle buffered file i/o and
  51.  * image output based on the introduced structs.
  52.  */
  53.  
  54. #define MAKESTMT(stuff)      do { stuff } while (0)
  55.  
  56. #define FGETC(fp, dest)   \
  57.   MAKESTMT( if (--(fp)->bytes_left < 0) (*(fp)->data_func)(fp); \
  58.         dest = *(fp)->pbuf++; )
  59.  
  60. #define FPUTC(fp, ch)   \
  61.   MAKESTMT( *(fp)->pbuf++ = ch; \
  62.         if (--(fp)->bytes_left == 0) (*(fp)->data_func)(fp); )
  63.  
  64. #define FCOPYC(src, des)   \
  65.   MAKESTMT( if (--(src)->bytes_left < 0) (*(src)->data_func)(src); \
  66.         *(des)->pbuf++ = *(src)->pbuf++; \
  67.         if (--(des)->bytes_left == 0) (*(des)->data_func)(des); )
  68.  
  69. #define ISKIPC(ip)   \
  70.   MAKESTMT( (ip)->pbuf++; \
  71.         if (--(ip)->bytes_left == 0) (*(ip)->put_line)(ip); )
  72.  
  73. #define IPUTC(ip, ch)   \
  74.   MAKESTMT( *(ip)->pbuf++ = ch; \
  75.         if (--(ip)->bytes_left == 0) (*(ip)->put_line)(ip); )
  76.  
  77. #define FICOPYC(src, des)   \
  78.   MAKESTMT( if (--(src)->bytes_left < 0) (*(src)->data_func)(src); \
  79.         *(des)->pbuf++ = *(src)->pbuf++; \
  80.         if (--(des)->bytes_left == 0) (*(des)->put_line)(des); )
  81.  
  82. /* Automatic HiByte/LoByte data conversion is provided by the
  83.  * following macros to avoid use of the standard ntohs/htons
  84.  * scheme here.
  85.  * This ensures unique interpretation/representation of external
  86.  * data in natural "Network" Order (HiByte first, then LoByte)
  87.  * by different hosts (especially for Intel-Systems).
  88.  */
  89.  
  90. #define FGETW(fp, dest)   \
  91.   MAKESTMT( if (--(fp)->bytes_left < 0) (*(fp)->data_func)(fp); \
  92.         dest = *((unsigned char *)(fp)->pbuf)++; \
  93.         dest <<= 8; \
  94.         if (--(fp)->bytes_left < 0) (*(fp)->data_func)(fp); \
  95.         dest |= *((unsigned char *)(fp)->pbuf)++; )
  96.  
  97. #define FPUTW(fp, wd)   \
  98.   MAKESTMT( *(fp)->pbuf++ = (char)(wd >> 8); \
  99.         if (--(fp)->bytes_left == 0) (*(fp)->data_func)(fp); \
  100.         *(fp)->pbuf++ = (char)wd; \
  101.         if (--(fp)->bytes_left == 0) (*(fp)->data_func)(fp); )
  102.  
  103.  
  104. /* Prototypes for public library functions. */
  105.  
  106. void level_3_decode(FBUFPUB *input, IBUFPUB *image);
  107.  
  108. IBUFPUB *encode_init(IMG_HEADER *input_header, FBUFPUB *output,
  109.              void *(*user_malloc)(long size),
  110.              void (*user_exit)(void),
  111.              short out_lev, short out_pat);
  112.  
  113. IBUFPUB *l3p2_encode_init(IMG_HEADER *input_header, FBUFPUB *output,
  114.               void *(*user_malloc)(long size),
  115.               void (*user_exit)(void));
  116.  
  117. IBUFPUB *l3p1_encode_init(IMG_HEADER *input_header, FBUFPUB *output,
  118.               void *(*user_malloc)(long size),
  119.               void (*user_exit)(void));
  120.  
  121. IBUFPUB *l2p2_encode_init(IMG_HEADER *input_header, FBUFPUB *output,
  122.               void *(*user_malloc)(long size),
  123.               void (*user_exit)(void));
  124.  
  125. IBUFPUB *l2p1_encode_init(IMG_HEADER *input_header, FBUFPUB *output,
  126.               void *(*user_malloc)(long size),
  127.               void (*user_exit)(void));
  128.  
  129. IBUFPUB *l1p2_encode_init(IMG_HEADER *input_header, FBUFPUB *output,
  130.               void *(*user_malloc)(long size),
  131.               void (*user_exit)(void));
  132.  
  133. IBUFPUB *l1p1_encode_init(IMG_HEADER *input_header, FBUFPUB *output,
  134.               void *(*user_malloc)(long size),
  135.               void (*user_exit)(void));
  136.